home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 32.0 KB | 1,113 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawSel.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef DRAWSEL_H
- #include "DrawSel.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef SHPTRAKR_H
- #include "ShpTrakr.h"
- #endif
-
- #ifndef DRAWCMDS_H
- #include "DrawCmds.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef DRWPRMSE_H
- #include "DrwPrmse.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw2
- #endif
-
- //========================================================================================
- // class CDrawSelection
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CDrawSelection
- //----------------------------------------------------------------------------------------
-
- CDrawSelection::CDrawSelection(Environment* ev, CDrawPart* drawPart):
- FW_CEmbeddingSelection(ev, TRUE, TRUE),
- fDrawPart(drawPart),
- fUpdateShape(NULL),
- fProxyShapeCount(0),
- fFrozenCount(0),
- fCount(0),
- fCollection(NULL),
- fWorkingHandle(FW_kZeroRect, FW_kFill)
- {
- fCollection = new FW_CPrivOrderedCollection;
- fWorkingHandle.SetInk(FW_kInvertInk);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::~CDrawSelection
- //----------------------------------------------------------------------------------------
-
- CDrawSelection::~CDrawSelection()
- {
- if (fUpdateShape)
- fUpdateShape->Release(somGetGlobalEnvironment());
-
- delete fCollection;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::WhichHandle
- //----------------------------------------------------------------------------------------
-
- CBaseShape* CDrawSelection::WhichHandle(Environment* ev, FW_CGraphicContext& gc, const FW_CPoint& mouse, short& whichHandle) const
- {
- whichHandle = 0;
-
- if (fCount != 0)
- {
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- whichHandle = shape->WhichHandle(gc, mouse);
- if (whichHandle != 0)
- return shape;
- }
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RenderSelectionHandles
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RenderSelectionHandles(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->RenderHandles(gc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RenderAllHandles
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RenderAllHandles(Environment* ev, FW_CFrame* frame)
- {
- if (fCount != 0)
- {
- FW_CFrameFacetIterator ite(ev, frame);
- for (ODFacet* facet = (ODFacet*)ite.First(ev); ite.IsNotComplete(ev); facet = (ODFacet*)ite.Next(ev))
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
- RenderSelectionHandles(ev, vc);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RenderHandles
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RenderHandles(Environment* ev, CBaseShape* shape)
- {
- FW_CPresentationFrameIterator ite(GetPresentation(ev));
- for (FW_CFrame* frame = ite.First(); ite.IsNotComplete(); frame = ite.Next())
- {
- if (frame->IsActive(ev))
- {
- FW_CFrameFacetIterator i(ev, frame);
- for (ODFacet* facet = i.First(ev); i.IsNotComplete(ev); facet = i.Next(ev))
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
- shape->RenderHandles(vc);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CloseSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::CloseSelection(Environment* ev)
- {
- while (fCollection->Count() != 0)
- {
- CBaseShape *shape = (CBaseShape*)fCollection->First();
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // turn off
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::AddToSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::AddToSelection(Environment* ev, CBaseShape* theShape, FW_Boolean renderHandles)
- {
- if (theShape != NULL)
- {
- DoAdd(ev, theShape);
- if (renderHandles)
- RenderHandles(ev, theShape); // Turn on
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RemoveFromSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RemoveFromSelection(Environment* ev, CBaseShape* shape, FW_Boolean renderHandles)
- {
- if (shape != NULL)
- {
- DoRemove(ev, shape);
- if (renderHandles)
- RenderHandles(ev, shape); // Turn Off
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DoAdd
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::DoAdd(Environment* ev, CBaseShape *shape)
- {
- shape->SelectShape(ev, TRUE);
- fCollection->AddLast(shape);
- fCount++;
- if (shape->GetShapeType() == kProxyShape)
- fProxyShapeCount++;
- if (shape->IsFrozen())
- fFrozenCount++;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DoRemove
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::DoRemove(Environment* ev, CBaseShape *shape)
- {
- shape->SelectShape(ev, FALSE);
- fCollection->Remove(shape);
- fCount--;
- if (shape->GetShapeType() == kProxyShape)
- fProxyShapeCount--;
- if (shape->IsFrozen())
- fFrozenCount--;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::ClearSelection
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::ClearSelection(Environment* ev)
- {
- CBaseShape *shape;
- while (fCollection->Count() != 0)
- {
- shape = (CBaseShape*)fCollection->First();
- shape->CheckPromise(ev, fDrawPart);
-
- DoRemove(ev, shape); // Remove from Selection list
- fDrawPart->RemoveShape(ev, shape); // Remove from shape list
- }
-
- CDrawFacetClipper facetClipper(ev, fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), fUpdateShape);
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- CalcCache(ev);
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectAll
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SelectAll(Environment* ev)
- {
- FW_CFrame* activeFrame = fDrawPart->GetActiveFrame(ev);
-
- RenderAllHandles(ev, activeFrame);
-
- FW_COrderedCollectionIterator ite(fDrawPart->GetShapeList());
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (!shape->IsSelectedShape())
- DoAdd(ev, shape);
- }
-
- RenderAllHandles(ev, activeFrame);
-
- CalcCache(ev);
-
- fDrawPart->SetTool(ev, kSelectTool);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsEmpty
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::IsEmpty(Environment* ev) const
- {
- return fCount == 0;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsSelectionOnlyOneProxy
- //----------------------------------------------------------------------------------------
-
- FW_MProxy* CDrawSelection::IsSelectionOnlyOneProxy(Environment* ev) const
- {
- if (fCount == 1 && fProxyShapeCount == 1)
- {
- return (CProxyShape*)fCollection->First();
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DoExternalizeSelection
- //----------------------------------------------------------------------------------------
- void CDrawSelection::DoExternalizeSelection(Environment* ev,
- ODStorageUnit* destinationSU,
- FW_CCloneInfo* cloneInfo)
- {
- // ----- Create an archive for our shapes -----
- FW_CStorageUnitSink sink(destinationSU, kODPropContents, fDrawPart->GetPartKind(ev));
- CDrawWritableStream archive(ev, &sink, cloneInfo);
-
- // ----- Write number of shapes -----
- unsigned long count = fCollection->Count();
- archive << count;
-
- // ----- Write top left offset -----
- FW_CFixed offset = FW_IntToFixed(0);
- archive << offset;
- archive << offset;
-
- // ----- Write shapes -----
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape* theShape = (CBaseShape*)ite.First(); ite.IsNotComplete(); theShape = (CBaseShape*)ite.Next())
- {
- FW_WRITE_DYNAMIC_OBJECT(archive, theShape, CBaseShape);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DoInternalizeSelection
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::DoInternalizeSelection(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo)
- {
- if (sourceSU->Exists(ev, kODPropContents, fDrawPart->GetPartKind(ev), 0))
- {
- // ----- Close First the current selection -----
- CloseSelection(ev);
-
- // ----- [HLX] force fulfill promises Otherwise bug in locks
- sourceSU->Focus(ev, kODPropContents, kODPosUndefined, fDrawPart->GetPartKind(ev), 0, kODPosUndefined);
- sourceSU->GetSize(ev);
-
- // ----- Create an archive object for the content property -----
- FW_CStorageUnitSink sink(sourceSU, kODPropContents, fDrawPart->GetPartKind(ev));
- CDrawReadableStream archive(ev, fDrawPart, &sink, cloneInfo);
-
- // ----- Read number of shapes -----
- unsigned long count;
- archive >> count;
-
- // ----- Read top left offset -----
- FW_CFixed xTopLeft, yTopLeft;
- archive >> xTopLeft;
- archive >> yTopLeft;
-
- // ----- Then read in the new selection -----
- for (unsigned short i = 0; i<count; i++)
- {
- CBaseShape* theShape = NULL;
- FW_READ_DYNAMIC_OBJECT(archive, &theShape, CBaseShape);
- FW_ASSERT(theShape);
-
- // ----- Add it at the right place -----
- fDrawPart->AddShape(ev, theShape);
-
- this->DoAdd(ev, theShape); // Add to the selection list
- }
-
- CalcCache(ev);
-
- return TRUE;
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::InsertNewPart
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::InsertNewPart(Environment* ev, FW_CFrame* scopeFrame)
- {
- FW_Boolean result = FW_CEmbeddingSelection::InsertNewPart(ev, scopeFrame);
-
- if (result)
- AdjustSelectionAfterPaste(ev, scopeFrame);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::AdjustSelectionAfterPaste
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CDrawSelection::AdjustSelectionAfterPaste(Environment* ev, FW_CFrame* scopeFrame)
- {
- FW_ASSERT(scopeFrame);
-
- fDrawPart->SetTool(ev, kSelectTool);
-
- FW_CRect frameBounds = scopeFrame->GetContentView(ev)->GetBounds(ev);
- frameBounds.Place(FW_kFixed0, FW_kFixed0);
- scopeFrame->GetContentView(ev)->ViewToViewContent(ev, frameBounds);
-
- FW_CRect box(fDragRect);
- box.PlaceInCenter(frameBounds);
-
- FW_CPoint result(box.left - fDragRect.left, box.top - fDragRect.top);
- OffsetSelection(ev, result.x, result.y);
-
- CDrawFacetClipper facetClipper(ev, fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), fUpdateShape);
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::Resize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::Resize(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- if (fClickedHandle == 0)
- return FALSE;
-
- if (!this->IsOKtoEdit(ev)) // can't resize read only part
- {
- FW_Beep();
- return TRUE;
- }
-
- if (!theMouseEvent.WaitUntilMouseMoved(ev))
- return TRUE;
-
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
-
- CBaseShape* anchorShape = GetAnchorShape();
-
- FW_PInk resizeInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- FW_PStyle resizeStyle(anchorShape->GetResizeStyle());
-
- CResizeTracker resizeTracker(ev, frame->GetContentView(ev), facet, anchorShape, fClickedHandle, resizeInk, resizeStyle, TRUE);
- if (resizeTracker.Track(ev, theMouseEvent))
- {
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- FW_CPoint lastLocation;
- resizeTracker.GetLastLocation(lastLocation);
- FW_CRect srcRect, dstRect;
- anchorShape->GetMapRects(fClickedHandle, lastLocation, srcRect, dstRect);
-
- CResizeShapeCommand* cmd = FW_NEW(CResizeShapeCommand,
- (ev, fDrawPart, frame, this,
- srcRect, dstRect));
- fDrawPart->ExecuteCommand(ev, cmd);
- }
- else
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
-
- anchorShape->CalcHandle(fClickedHandle, &fWorkingHandle);
- fWorkingHandle.Render(vc); // redraw the handle
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CalcCache
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::CalcCache(Environment* ev)
- {
- fDragRect.Clear();
-
- if (fUpdateShape == NULL)
- fUpdateShape = ::FW_NewODShape(ev);
-
- if (fCount == 0)
- return;
-
- FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
- FW_CRect tempRect;
-
- FW_Boolean first = TRUE;
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->GetDragRect(tempRect);
- shape->GetUpdateBox(ev, aqTempShape);
- if (first)
- {
- fDragRect = tempRect;
- fUpdateShape->CopyFrom(ev, aqTempShape);
- }
- else
- {
- fDragRect |= tempRect;
- fUpdateShape->Union(ev, aqTempShape);
- }
-
- first = FALSE;
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CreateSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CDrawSelection::CreateSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- FW_UNUSED(frame);
- FW_UNUSED(facet);
-
- ODShape* shape = ::FW_NewODShape(ev, fDragRect);
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CreateSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CDrawSelection::CreateSelectionOutline(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- ODShape* outline = GetAnchorShape()->CreateShapeOutline(ev);
-
- if (fCount > 1)
- {
- FW_CAcquiredODShape shapeOutline = FW_CEmbeddingSelection::CreateSelectionOutline(ev, facet, frame);
- outline->Union(ev, shapeOutline);
- }
-
- return outline;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::MapSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::MapSelection(Environment* ev, const FW_CRect& srcRect, const FW_CRect& dstRect)
- {
- FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->MapShape(ev, fDrawPart, srcRect, dstRect);
- }
-
- CalcCache(ev);
-
- aqUnionShape->Union(ev, fUpdateShape);
-
- CDrawFacetClipper facetClipper(ev, fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CreateSelectionFrameShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CDrawSelection::CreateSelectionFrameShape(Environment* ev) const
- {
-
- FW_CRect selectionRect(fDragRect);
- selectionRect.Place(FW_kZeroPoint);
-
- ODShape* selectionShape = ::FW_NewODShape(ev, selectionRect);
- return selectionShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::OffsetSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::OffsetSelection(Environment* ev, FW_CFixed xDelta, FW_CFixed yDelta)
- {
- FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->OffsetShape(ev, xDelta, yDelta);
- }
-
- CalcCache(ev);
-
- aqUnionShape->Union(ev, fUpdateShape);
-
- CDrawFacetClipper facetClipper(ev, fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectWithRectangle
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SelectWithRectangle(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- CRectShape rectShape; // Create a rect shape on the stack
- FW_PStyle trackStyle(FW_IntToFixed(1), FW_kAntPat);
- FW_PInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- rectShape.ChangeRenderVerb(ev, fDrawPart, kFrameOnly);
- rectShape.SetFrameInk(trackInk);
- rectShape.SetFrameStyle(trackStyle);
-
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
-
- CShapeTracker tracker(ev, frame->GetContentView(ev), facet, &rectShape, FALSE);
- if (tracker.Track(ev, theMouseEvent))
- {
- FW_Boolean isShift = theMouseEvent.IsExtendModifier(ev);
- FW_CRect selectRect;
- rectShape.GetRectGeometry(selectRect);
-
- FW_COrderedCollectionIterator ite(fDrawPart->GetShapeList());
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->InSelectionRect(selectRect))
- {
- if (shape->IsSelectedShape())
- {
- if (isShift)
- {
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // Turn Off
- }
- }
- else
- {
- DoAdd(ev, shape);
- RenderHandles(ev, shape); // Turn on
- }
- }
- else if (shape->IsSelectedShape() && !isShift)
- {
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // Turn Off
- }
- }
- CalcCache(ev);
- }
- else
- {
- if (!theMouseEvent.IsExtendModifier(ev))
- CloseSelection(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::ChangeSelectionPenSize
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::ChangeSelectionPenSize(Environment* ev, FW_CFixed newPenSize)
- {
- FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->ChangePenSize(ev, fDrawPart, newPenSize);
- this->RedrawShape(ev, shape);
- }
-
- SelectionChanged(ev);
- CalcCache(ev);
-
- aqUnionShape->Union(ev, fUpdateShape);
-
- CDrawFacetClipper facetClipper(ev, fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::ChangeSelectionColor
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::ChangeSelectionColor(Environment* ev, const FW_CColor& color, FW_Boolean changeFill)
- {
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (changeFill)
- shape->ChangeFillColor(ev, fDrawPart, color);
- else
- shape->ChangeFrameColor(ev, fDrawPart, color);
-
- this->RedrawShape(ev, shape);
- }
-
- SelectionChanged(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::ChangeSelectionPattern
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::ChangeSelectionPattern(Environment* ev, const FW_PPattern& pattern, FW_Boolean changeFill)
- {
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (changeFill)
- shape->ChangeFillPattern(ev, fDrawPart, pattern);
- else
- shape->ChangeFramePattern(ev, fDrawPart, pattern);
-
- this->RedrawShape(ev, shape);
- }
-
- SelectionChanged(ev);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::ChangeSelectionRenderVerb
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::ChangeSelectionRenderVerb(Environment* ev, unsigned short newRenderVerb)
- {
- FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->ChangeRenderVerb(ev, fDrawPart, newRenderVerb);
- this->RedrawShape(ev, shape);
- }
-
- SelectionChanged(ev);
- CalcCache(ev);
-
- aqUnionShape->Union(ev, fUpdateShape);
-
- CDrawFacetClipper facetClipper(ev, fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RedrawShape
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RedrawShape(Environment* ev, CBaseShape *shape)
- {
- FW_CAcquiredODShape aqInvalidShape = ::FW_NewODShape(ev);
- shape->GetUpdateBox(ev, aqInvalidShape);
- GetPresentation(ev)->Invalidate(ev, aqInvalidShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SetFrozen
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SetFrozen(Environment* ev, FW_Boolean state)
- {
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->SetFrozen(state))
- {
- state ? fFrozenCount++ : fFrozenCount--;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::NewPromise
- //----------------------------------------------------------------------------------------
-
- FW_CPromise* CDrawSelection::NewPromise(Environment* ev, ODUpdateID updateID, FW_EStorageKinds storageKind, FW_CFrame* scopeFrame, ODCloneKind cloneKind)
- {
- FW_UNUSED(cloneKind);
-
- if (storageKind == FW_kLinkStorage)
- return NULL;
-
- return new CDrawPromise(ev, updateID, storageKind, fDrawPart, scopeFrame, this);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectionChanged
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SelectionChanged(Environment* ev)
- {
- FW_CPrivOrderedCollection temp;
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->IsPublished())
- {
- FW_Boolean add = TRUE;
- FW_COrderedCollectionIterator tempIte(&temp);
- for (CDrawPublishLink* link = (CDrawPublishLink*)tempIte.First(); tempIte.IsNotComplete(); link = (CDrawPublishLink*)tempIte.Next())
- {
- if (shape->GetPublishLink() == link)
- {
- add = FALSE;
- break;
- }
- }
-
- if (add)
- temp.AddLast(shape->GetPublishLink());
- }
- }
-
- FW_COrderedCollectionIterator tempIte(&temp);
- for (CDrawPublishLink* link = (CDrawPublishLink*)tempIte.First(); tempIte.IsNotComplete(); link = (CDrawPublishLink*)tempIte.Next())
- {
- link->ContentUpdated(ev, fDrawPart->GetSession(ev)->UniqueUpdateID(ev));
- }
-
- temp.RemoveAll();
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsSelectionPublishable
- //----------------------------------------------------------------------------------------
- // We don't allow linking if one of the shape is already published
-
- FW_Boolean CDrawSelection::IsSelectionPublishable(Environment* ev)
- {
- FW_Boolean result = TRUE;
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->IsPublished())
- {
- result = FALSE;
- break;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CanSubscribe
- //----------------------------------------------------------------------------------------
- FW_Boolean CDrawSelection::CanSubscribe(Environment* ev, ODPasteAsMergeSetting& setting)
- {
- FW_Boolean result = TRUE;
-
- if (fAllowSubscribe)
- {
- setting = kODPasteAsMerge; // default is no embedding
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->IsSubscribed())
- {
- result = FALSE;
- break;
- }
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsMouseInDraggableItem
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::IsMouseInDraggableItem(Environment* ev, FW_CFrame* frame,
- const FW_CMouseEvent& theMouseEvent, FW_Boolean inBackground)
- {
- fClickedHandle = 0;
- fAnchorShape = NULL;
-
- if (fDrawPart->GetTool() != kSelectTool)
- return FALSE;
-
- FW_CViewContext vc(ev, frame->GetContentView(ev), theMouseEvent.GetFacet(ev));
-
- // ----- Look first for a handle -----
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- frame->GetContentView(ev)->FrameToViewContent(ev, where);
-
- CBaseShape* clickedShape = WhichHandle(ev, vc, where, fClickedHandle);
- if (clickedShape != NULL)
- {
- fAnchorShape = clickedShape;
- return FALSE; // if in a handle we won't drag
- }
-
- // ----- then look for a selected shape -----
- fAnchorShape = fDrawPart->WhichShape(ev, vc, theMouseEvent, TRUE);
-
- return fAnchorShape != NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::UpdateSelectionOnMouseDown
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::UpdateSelectionOnMouseDown(Environment* ev,
- const FW_CMouseEvent& mouseEvent,
- ODFacet* embeddedFacet,
- FW_Boolean inEmbeddedFrameBorder,
- FW_Boolean inBackground)
- {
- if (inEmbeddedFrameBorder)
- {
- fClickedHandle = 0;
- fAnchorShape = NULL;
-
- CProxyShape *theShape = (CProxyShape*)fDrawPart->GetProxy(ev, embeddedFacet->GetFrame(ev));
-
- // [HLX] I have to remove this assert for now. See FW_CFrame::FocusStateChanged
- // FW_ASSERT(!theShape->IsSelectedShape());
- CloseSelection(ev); // Should already be closed
- AddToSelection(ev, theShape, TRUE);
-
- fAnchorShape = theShape;
- }
- else if (fDrawPart->GetTool() == kSelectTool)
- {
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
- FW_CViewContext vc(ev, frame->GetContentView(ev), mouseEvent.GetFacet(ev));
-
- CBaseShape* clickedShape = fDrawPart->WhichShape(ev, vc, mouseEvent, FALSE);
- if (clickedShape)
- {
- if (mouseEvent.IsExtendModifier(ev))
- {
- if (clickedShape->IsSelectedShape())
- RemoveFromSelection(ev, clickedShape, TRUE);
- else
- AddToSelection(ev, clickedShape, TRUE);
- }
- else if (!clickedShape->IsSelectedShape())
- {
- CloseSelection(ev);
- AddToSelection(ev, clickedShape, TRUE);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DeleteSelection
- //----------------------------------------------------------------------------------------
- void CDrawSelection::DeleteSelection(Environment* ev)
- {
- CBaseShape *shape;
- while (fCollection->Count() != 0)
- {
- shape = (CBaseShape*)fCollection->First();
- DoRemove(ev, shape); // Remove from Selection list
- fDrawPart->DeleteShape(ev, shape); // Remove from shape list
- delete shape;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsOKtoEdit
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::IsOKtoEdit(Environment* ev)
- {
- if (fDrawPart->IsReadOnly(ev)) // can't edit read only part
- return FALSE;
-
- // check whether any of the selected shapes is in a link destination
- FW_COrderedCollectionIterator iter(fCollection);
- for (CBaseShape *shape = (CBaseShape*)iter.First(); iter.IsNotComplete(); shape = (CBaseShape*)iter.Next())
- {
- if (shape->IsSubscribed())
- return FALSE; // can't edit a subscribed shape
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::GetSelectionPenSize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::GetSelectionPenSize(Environment* ev, FW_CFixed& penSize)
- {
- FW_COrderedCollectionIterator iter(fCollection);
- FW_Boolean first = TRUE;
- for (CBaseShape *shape = (CBaseShape*)iter.First(); iter.IsNotComplete(); shape = (CBaseShape*)iter.Next())
- {
- if (first)
- {
- penSize = shape->GetPenSize();
- first = FALSE;
- }
- else
- {
- if (shape->GetPenSize() != penSize)
- return FALSE;
- }
- }
-
- return TRUE;
- }
-